﻿using GameServer.Model;
using Summer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameServer.Mgr
{
    /// <summary>
    /// 每个地图都有
    /// </summary>
    public class MonsterManager
    {
        private Space _space;
        private Dictionary<int,Monster> dict = new Dictionary<int,Monster>();
        public void Init(Space space)
        {
            _space = space;
        }
        public Monster Create(int id,int typeID,Vector3Int pos,Vector3Int dir)
        {
            //ToDo根据你想创建的TypeID去和Json里面的进行比对,然后把Json里面的数据取出来,取出来存到Monster类里面，再加入地图的时候发给玩家
            if (DataManager.Instance.MonsterDict.ContainsKey(typeID))
            {
                Monster monster = new Monster(id,pos, dir, DataManager.Instance.MonsterDict[typeID].speed)
                {
                    type_id=typeID,
                    entity_id=id,
                    level= DataManager.Instance.MonsterDict[typeID].level,
                    name = DataManager.Instance.MonsterDict[typeID].name,
                    gold= DataManager.Instance.MonsterDict[typeID].gold,
                    hp= DataManager.Instance.MonsterDict[typeID].hp,
                    mp= DataManager.Instance.MonsterDict[typeID].mp,
                    attack= DataManager.Instance.MonsterDict[typeID].attack,
                    defense= DataManager.Instance.MonsterDict[typeID].defense,
                    magic= DataManager.Instance.MonsterDict[typeID].magic,
                    magicdefense= DataManager.Instance.MonsterDict[typeID].magicdefense,
                    speed= DataManager.Instance.MonsterDict[typeID].speed,
                    baoji=DataManager.Instance.MonsterDict[typeID].baoji,
                    baojidefense= DataManager.Instance.MonsterDict[typeID].baojidefense
                };
                monster.Position = pos;
                monster.Direction = dir;
                monster.initPosition = pos;
                EntityManager.Instance.AddEntity(_space.Id, monster);
                monster.spaceId = _space.Id;
                dict[monster.entityId] = monster;
                this._space.MonsterEnter(monster);
                return monster;
            }
            else return null;
            
        }
    }
}
